//
//  HomeNavigation.m
//  huangjinbao
//
//  Created by hjb-ios on 16/6/27.
//  Copyright © 2016年 hjb-ios. All rights reserved.
//
#define screenWidth [[UIScreen mainScreen] bounds].size.width
#define screenHeight [[UIScreen mainScreen] bounds].size.height
#import "HomeNavigation.h"
//#import "CATextLayer+NumberJump.h"
@implementation HomeNavigation{
  
}
-(id)initWithTag:(int)viewTag title:(NSString*)title handler:(tapBack)tapBack{
    
    if(viewTag==1){
        self = [super initWithFrame:CGRectMake(0, 0, screenWidth, SafeAreaTopHeight)];
        self.tapBack = tapBack;
       self.img=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, screenWidth, SafeAreaTopHeight)];
        
        self.img.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1];
       
        self.img.userInteractionEnabled =YES;
        [self addSubview:self.img];
        textLayer = [[CATextLayer alloc] init];
        textLayer.string = @"";
        textLayer.frame = CGRectMake(screenWidth/2-50, 30, 100, 44);
        textLayer.backgroundColor = [UIColor clearColor].CGColor;
        textLayer.alignmentMode = kCAAlignmentLeft;//字体的对齐方式
        textLayer.contentsScale=4;
        textLayer.fontSize=18;
//        textLayer.foregroundColor =yellow.CGColor;//字体的颜色
        [self.img.layer addSublayer:textLayer];
       
        UIButton * but = [[UIButton alloc]initWithFrame:CGRectMake(screenWidth/3, 0, screenWidth/3, SafeAreaTopHeight)];
        [self.img addSubview:but];
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, SafeAreaTopHeight-44, screenWidth, 44)];
        _titleLabel.text = title;
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.textColor =[UIColor colorWithRed:34/255.0 green:34/255.0 blue:34/255.0 alpha:1];
        [_titleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:17*kfit]];
        [self.img addSubview:_titleLabel];
          //   左按钮
        self.leftbut = [[UIButton alloc]initWithFrame:CGRectMake(0, SafeAreaTopHeight-44, 44, 44)];
        
        [self.leftbut setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];

        self.leftbut.tag = 0;
//        [self.leftbut setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        self.leftbut.backgroundColor = [UIColor clearColor];
        [self.leftbut addTarget:self action:@selector(backClick:) forControlEvents:UIControlEventTouchUpInside];
//        [self.img addSubview:leftImg];
        [self.img addSubview:self.leftbut];
        UIView *line = [[UIView alloc]initWithFrame:CGRectMake(0, SafeAreaTopHeight-0.5, screenWidth, 0.5)];
        line.backgroundColor = [UIColor colorWithRed:229/255.0 green:229/255.0 blue:229/255.0 alpha:1];
        [self.img addSubview:line];
    }else if (viewTag==3){
        self = [super initWithFrame:CGRectMake(0, 0, screenWidth, SafeAreaTopHeight)];
        self.tapBack = tapBack;
        self.img=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, screenWidth, SafeAreaTopHeight)];
        
        self.img.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1];
        
        self.img.userInteractionEnabled =YES;
        [self addSubview:self.img];
        textLayer = [[CATextLayer alloc] init];
        textLayer.string = @"";
        textLayer.frame = CGRectMake(screenWidth/2-50, 30, 100, 44);
        textLayer.backgroundColor = [UIColor clearColor].CGColor;
        textLayer.alignmentMode = kCAAlignmentLeft;//字体的对齐方式
        textLayer.contentsScale=4;
        textLayer.fontSize=18;
        //        textLayer.foregroundColor =yellow.CGColor;//字体的颜色
        [self.img.layer addSublayer:textLayer];
        
        UIButton * but = [[UIButton alloc]initWithFrame:CGRectMake(screenWidth/3, 0, screenWidth/3, SafeAreaTopHeight)];
        [self.img addSubview:but];
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, SafeAreaTopHeight-44, screenWidth, 44)];
        _titleLabel.text = title;
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.textColor =[UIColor whiteColor];
        [_titleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:17*kfit]];
        [self.img addSubview:_titleLabel];
        //   左按钮
        self.leftbut = [[UIButton alloc]initWithFrame:CGRectMake(0, SafeAreaTopHeight-44, 44, 44)];
        
        [self.leftbut setImage:[UIImage imageNamed:@"back_white"] forState:UIControlStateNormal];
        
        self.leftbut.tag = 0;
        //        [self.leftbut setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        self.leftbut.backgroundColor = [UIColor clearColor];
        [self.leftbut addTarget:self action:@selector(backClick:) forControlEvents:UIControlEventTouchUpInside];
        //        [self.img addSubview:leftImg];
        [self.img addSubview:self.leftbut];
        UIView *line = [[UIView alloc]initWithFrame:CGRectMake(0, SafeAreaTopHeight-0.5, screenWidth, 0.5)];
        line.backgroundColor = [UIColor colorWithRed:229/255.0 green:229/255.0 blue:229/255.0 alpha:1];
        [self.img addSubview:line];
        
    }else if (viewTag==4){
        self = [super initWithFrame:CGRectMake(0, 0, screenWidth, SafeAreaTopHeight)];
        self.tapBack = tapBack;
        self.img=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, screenWidth, SafeAreaTopHeight)];
        
        self.img.backgroundColor = [UIColor clearColor];
        
        self.img.userInteractionEnabled =YES;
        [self addSubview:self.img];
        textLayer = [[CATextLayer alloc] init];
        textLayer.string = @"";
        textLayer.frame = CGRectMake(screenWidth/2-50, 30, 100, 44);
        textLayer.backgroundColor = [UIColor clearColor].CGColor;
        textLayer.alignmentMode = kCAAlignmentLeft;//字体的对齐方式
        textLayer.contentsScale=4;
        textLayer.fontSize=18;
        //        textLayer.foregroundColor =yellow.CGColor;//字体的颜色
        [self.img.layer addSublayer:textLayer];
        
        UIButton * but = [[UIButton alloc]initWithFrame:CGRectMake(screenWidth/3, 0, screenWidth/3, SafeAreaTopHeight)];
        [self.img addSubview:but];
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, SafeAreaTopHeight-44, screenWidth, 44)];
        _titleLabel.text = title;
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.textColor =[UIColor whiteColor];
        [_titleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:17*kfit]];
        [self.img addSubview:_titleLabel];
        //   左按钮
        self.leftbut = [[UIButton alloc]initWithFrame:CGRectMake(0, SafeAreaTopHeight-44, 44, 44)];
        
        [self.leftbut setImage:[UIImage imageNamed:@"back_white"] forState:UIControlStateNormal];
        
        self.leftbut.tag = 0;
        //        [self.leftbut setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        self.leftbut.backgroundColor = [UIColor clearColor];
        [self.leftbut addTarget:self action:@selector(backClick:) forControlEvents:UIControlEventTouchUpInside];
        //        [self.img addSubview:leftImg];
        [self.img addSubview:self.leftbut];
        UIView *line = [[UIView alloc]initWithFrame:CGRectMake(0, SafeAreaTopHeight-0.5, screenWidth, 0.5)];
        line.backgroundColor = [UIColor colorWithRed:229/255.0 green:229/255.0 blue:229/255.0 alpha:1];
//        [self.img addSubview:line];
        
    }else{
        self = [super initWithFrame:CGRectMake(0, -20, screenWidth, SafeAreaTopHeight)];
        self.tapBack = tapBack;
        self.img=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, screenWidth, SafeAreaTopHeight)];
        self.img.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1];
        self.img.userInteractionEnabled =YES;
        [self addSubview:self.img];
        textLayer = [[CATextLayer alloc] init];
        textLayer.string = @"";
        textLayer.frame = CGRectMake(screenWidth/2-50, 30, 100, 44);
        textLayer.backgroundColor = [UIColor clearColor].CGColor;
        textLayer.alignmentMode = kCAAlignmentLeft;//字体的对齐方式
        textLayer.contentsScale=4;
        textLayer.fontSize=18;
        //        textLayer.foregroundColor =yellow.CGColor;//字体的颜色
        [self.img.layer addSublayer:textLayer];
        
        UIButton * but = [[UIButton alloc]initWithFrame:CGRectMake(screenWidth/3, 0, screenWidth/3, SafeAreaTopHeight)];
        [self.img addSubview:but];
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, SafeAreaTopHeight-44, screenWidth, 44)];
        _titleLabel.text = title;
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.textColor =[UIColor colorWithRed:34/255.0 green:34/255.0 blue:34/255.0 alpha:1];
        [_titleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:17*kfit]];
        [self.img addSubview:_titleLabel];
        //   左按钮
        self.leftbut = [[UIButton alloc]initWithFrame:CGRectMake(0, SafeAreaTopHeight-44, 44, 44)];
        [self.leftbut setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
        //    [leftbut setTitle:@"黄金公社" forState:UIControlStateNormal];
        self.leftbut.tag = 0;
        [self.leftbut setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.leftbut addTarget:self action:@selector(backClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.img addSubview:self.leftbut];
        UIView *line = [[UIView alloc]initWithFrame:CGRectMake(0, SafeAreaTopHeight-0.5, screenWidth, 0.5)];
        line.backgroundColor = [UIColor colorWithRed:229/255.0 green:229/255.0 blue:229/255.0 alpha:1];
        [self.img addSubview:line];
    }
  
   
  
    
    return  self;
}

-(void)backClick:(UIButton*)sender{
    if (self.tapBack) {
        self.tapBack(sender);
    }
}


@end
